﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PFB_Functions
{
    class Program
    {
        public static void Main(string[] args)
        {
            int n = 20;
            int min = 1;
            int max = 100;

            int[] array = GetRandomArray(n, min, max);

            Console.WriteLine("--------------------");

            PrintArray(array);

            Console.WriteLine("--------------------");

            int minArray = MinArray(array);
            int maxArray = MaxArray(array);
            int sumArray = SumArray(array);
            int avrArray = sumArray / n;

            Console.WriteLine("Array Min = " + minArray);
            Console.WriteLine("Array Max = " + maxArray);
            Console.WriteLine("Array Sum = " + sumArray);
            Console.WriteLine("Array Avr = " + avrArray);

            Console.ReadKey();
        }

        static int SumArray(int[] array)
        {
            int n = array.Length;
            int s = 0;

            for (int i = 0; i < n; i++)
            {
                s += array[i];
            }

            return s;
        }

        static int MaxArray(int[] array)
        {
            int max = array[0];

            for (int i = 1; i < array.Length; i++)
            {
                max = Max(max, array[i]);
                //max = Math.Max(max, array[i]);
            }

            return max;
        }

        static int Max(int a, int b)
        {
            if (a > b)
            {
                return a;
            }
            else
            {
                return b;
            }
        }

        static int MinArray(int[] array)
        {
            int min = array[0];

            for (int i = 1; i < array.Length; i++)
            {
                min = Min(min, array[i]);
                //max = Math.Min(min, array[i]);
            }

            return min;
        }

        static int Min(int a, int b)
        {
            if (a < b)
            {
                return a;
            }
            else
            {
                return b;
            }
        }

        static void PrintArray(int[] array)
        {
            for (int i = 0; i < array.Length; i++)
            {
                Console.WriteLine("array[{0}] = {1}", i, array[i]);
            }
        }

        static int[] GetRandomArray(int n, int min, int max)
        {
            int[] array = new int[n];

            Random rnd = new Random();

            for (int i = 0; i < n; i++)
            {
                array[i] = rnd.Next(min, max);
            }

            return array;
        }
    }
}
